home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / mpeg / gdith.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  161 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <math.h>
  22. #include "video.h"
  23. #include "proto.h"
  24. #include "dither.h"
  25.  
  26. /* Range values for lum, cr, cb. */
  27. int LUM_RANGE;
  28. int CR_RANGE;
  29. int CB_RANGE;
  30.  
  31. /* Array that remaps color numbers to actual pixel values used by X server. */
  32.  
  33. unsigned char pixel[256];
  34.  
  35. /* Arrays holding quantized value ranged for lum, cr, and cb. */
  36.  
  37. int *lum_values;
  38. int *cr_values;
  39. int *cb_values;
  40.  
  41. /*
  42.  *--------------------------------------------------------------
  43.  *
  44.  * InitColor --
  45.  *
  46.  *    Initialized lum, cr, and cb quantized range value arrays.
  47.  *
  48.  * Results: 
  49.  *      None.
  50.  *
  51.  * Side effects:
  52.  *      None.
  53.  *
  54.  *--------------------------------------------------------------
  55.  */
  56.  
  57. void
  58. InitColor()
  59. {
  60.   int i;
  61.   static int initcolor_ok;
  62.  
  63.   if(!initcolor_ok)
  64.   {
  65.  
  66.     for (i=0; i<LUM_RANGE; i++) {
  67.       lum_values[i] = ((i * 256) / (LUM_RANGE)) + (256/(LUM_RANGE*2));
  68.     }
  69.  
  70.     for (i=0; i<CR_RANGE; i++) {
  71.       cr_values[i] = ((i * 256) / (CR_RANGE)) + (256/(CR_RANGE*2));
  72.     }
  73.  
  74.     for (i=0; i<CB_RANGE; i++) {
  75.       cb_values[i] = ((i * 256) / (CB_RANGE)) + (256/(CB_RANGE*2));
  76.     }
  77.   }
  78.   initcolor_ok = 1;
  79. }
  80.  
  81. #if 0
  82.  
  83. /*
  84.  *--------------------------------------------------------------
  85.  *
  86.  * ConvertColor --
  87.  *
  88.  *    Given a l, cr, cb tuple, converts it to r,g,b.
  89.  *
  90.  * Results:
  91.  *    r,g,b values returned in pointers passed as parameters.
  92.  *
  93.  * Side effects:
  94.  *      None.
  95.  *
  96.  *--------------------------------------------------------------
  97.  */
  98.  
  99. static void
  100. ConvertColor(l, cr, cb, r, g, b)
  101.      unsigned char l, cr, cb;
  102.      unsigned char *r, *g, *b;
  103. {
  104.   double fl, fcr, fcb, fr, fg, fb;
  105.  
  106.   fl = (double) l;
  107.   fcr =  ((double) cr) - 128.0;
  108.   fcb =  ((double) cb) - 128.0;
  109.  
  110.  
  111.   fr = fl + (1.40200 * fcb);
  112.   fg = fl - (0.71414 * fcb) - (0.34414 * fcr);
  113.   fb = fl + (1.77200 * fcr);
  114.  
  115.   if (fr < 0.0) fr = 0.0;
  116.   else if (fr > 255.0) fr = 255.0;
  117.  
  118.   if (fg < 0.0) fg = 0.0;
  119.   else if (fg > 255.0) fg = 255.0;
  120.  
  121.   if (fb < 0.0) fb = 0.0;
  122.   else if (fb > 255.0) fb = 255.0;
  123.  
  124.   *r = (unsigned char) fr;
  125.   *g = (unsigned char) fg;
  126.   *b = (unsigned char) fb;
  127.  
  128. }
  129.  
  130. #endif
  131. /*
  132.  *--------------------------------------------------------------
  133.  *
  134.  * ExecuteDisplay --
  135.  *
  136.  *    Actually displays display plane in previously created window.
  137.  *
  138.  * Results:
  139.  *    None.
  140.  *
  141.  * Side effects:
  142.  *    None.
  143.  *
  144.  *--------------------------------------------------------------
  145.  */
  146. #if 0
  147. void
  148. ExecuteDisplay(vid_stream)
  149.      VidStream *vid_stream;
  150. {
  151.  
  152. #if 0
  153.   totNumFrames++;
  154.   if (!quietFlag) {
  155.     fprintf (stderr, "%d\r", totNumFrames);
  156.   }
  157. #endif
  158. }
  159.  
  160. #endif
  161.